import Vue from 'vue';
import axios from './router/axios';
import VueAxios from 'vue-axios';
import App from './App';
import router from './router/router';
import './permission'; // 权限
import './error'; // 日志
import './cache';//页面缓冲
import store from './store';
import { loadStyle } from './util/util'
import * as urls from '@/config/env';
import Element from 'element-ui';
import arrayFn from '@/util/arrayUtil';
import {
  iconfontUrl,
  iconfontVersion
} from '@/config/env';
import basicContainer from './components/basic-container/main';
import i18n from './lang' // Internationalization
import './styles/common.scss';
import "../public/icon/iconfont.css";


import VideoPlayer from 'vue-video-player';
require('video.js/dist/video-js.css')
require('vue-video-player/src/custom-theme.css')



import VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import AvueUeditor from 'avue-plugin-ueditor'

import config from '@/config/website'
let RCecharts = require('echarts')
Vue.prototype.$config = config
Vue.prototype.$ECHARTS = RCecharts

// import '../public/cdn/page/styles/element-variables.scss'

Vue.use(AvueUeditor);
Vue.use(VueQuillEditor)
Vue.use(VideoPlayer)
Vue.use(router)
Vue.use(VueAxios, axios)
Vue.use(Element, {
  i18n: (key, value) => i18n.t(key, value)
})
Vue.use(window.AVUE, {
  i18n: (key, value) => i18n.t(key, value)
})
//注册全局容器
Vue.component('basicContainer', basicContainer);
//自定义指令控制自定义按钮
Vue.directive('has',{
  bind:function(el,binding){
    // 获取按钮权限
    if (!store.getters.permission[binding.value]) {
      //移除不匹配的按钮
      el.parentNode.removeChild(el);
    }
  }
});

// 价格过大时的处理
Vue.filter('priceFilter',(val)=>{
	if(val){
		val=val.toString()
		if(val.indexOf('-') == -1){//一个价格
			val=Number(val)
			if(val > 9999.99) {
				let a = val / 10000
				let b = ( parseInt( a * 100 ) / 100 ).toFixed(2)
				console.log(b + '万')
				return b + '万'
			}
			if(val){
				return val.toFixed(2)
			}else if(val==0){
				return '0.00';
			}
		}else{//区间价格
			let num=val.split('-')
			let num0=Number(num[0])
			if(num0 > 9990.99) {
				let a = val / 10000
				let b = ( parseInt( a * 100 ) / 100 ).toFixed(2)
				console.log(b + '万')
				num0 = b + '万'
			}
			let num1=Number(num[1])
			if(num1 > 9999.99) {
				let a = val / 10000
				let b = ( parseInt( a * 100 ) / 100 ).toFixed(2)
				console.log(b + '万')
				num1 = b + '万'
			}
			return num0+'-'+num1
		}
	}else{
		return '0.00';
	}
})

// 加载相关url地址
Object.keys(urls).forEach(key => {
  Vue.prototype[key] = urls[key];
})
// 动态加载阿里云字体库
iconfontVersion.forEach(ele => {
  loadStyle(iconfontUrl.replace('$key', ele));
})
Vue.prototype.$EventBus = new Vue();
Vue.config.productionTip = false;

Vue.prototype.arrayFn = arrayFn;
new Vue({
  router,
  store,
  i18n,
  render: h => h(App)
}).$mount('#app')
